#ifndef EDITOR_H
#define EDITOR_H

#include <QObject>
#include <QPlainTextEdit>
#include <QWidget>
#include <QString>
#include <QPaintEvent>
#include <QMouseEvent>
#include "linenumberarea.h"

class Editor : public QPlainTextEdit
{
public:
    Editor(QWidget* parent = nullptr);

public:
    void setFileName(const QString& filename) { _fileName = filename; }
    QString getFileName() const { return _fileName; }
    bool saveFile();
    void paintLineNumberArea(QPaintEvent* event);
    void lineNumberMousePress(QMouseEvent* event);

protected:
    void resizeEvent(QResizeEvent* event);

private:
    QWidget* _parent;
    QString _fileName;
    LineNumberArea* _lineNumberArea = nullptr;
    int getLineNumberAreaWidth();
    void highlightLine();

private slots:
    void updateLineNumberArea(const QRect &rect, int dy);
    void updateLineNumberAreaWidth();
    void unHighlightLine();
};

#endif // EDITOR_H
